dc_trt <- tracts("District of Columbia", year=2019)
dc_trt_trans <- st_transform(dc_trt,
"+proj=longlat +datum=WGS84")
dc_trt[1:2,]
leaflet() %>%
addTiles() %>%
addPolygons(data=dc_trt_trans,
popup = ~NAME)
dc_bg <- block_groups("District of Columbia", year=2019)
dc_bg_trans <- st_transform(dc_bg, "+proj=longlat +datum=WGS84")
dc_blk <- blocks("District of Columbia", year=2019)
dc_blk_trans <- st_transform(dc_blk, "+proj=longlat +datum=WGS84")
leaflet() %>%
addTiles() %>%
addPolygons(data=dc_trt_trans,
popup = ~NAME) %>%
addPolygons(data=dc_bg_trans,
popup = ~GEOID,
color = "red",
weight = 1,
opacity= 1,
smoothFactor = 1,
fillOpacity = 0,
fillColor= "#BDBDC3"
)
leaflet() %>%
addTiles() %>%
addPolygons(data=dc_trt_trans,
popup = ~NAME,
fillOpacity = 0,
fillColor= "snow") %>%
addPolygons(data=dc_bg_trans,
popup = ~GEOID,
color = "red",
weight = 2,
opacity= 0.8,
smoothFactor = 1,
fillOpacity = 0,
fillColor= "snow") %>%
addPolygons(data=dc_blk_trans,
popup = ~GEOID10,
color = "green",
weight = 0.7,
opacity= 2,
smoothFactor = 1,
fillOpacity = 0,
fillColor= "snow")
##Now are selecting only a few blockgroups (will need to do this for project)
dc_bg_select<-dc_bg_trans [31:40,]
leaflet() %>%
addTiles() %>%
addPolygons(data=dc_trt_trans,
popup = ~NAME) %>%
addPolygons(data=dc_bg_select,
color = "red",
weight = 1,
popup = ~GEOID)
api_key <-"c3d3ea517c64b3c262d71c51135e449f6d98bf24"
# Request at https://api.census.gov/data/key_signup.html
census_api_key(key=api_key)
## To install your API key for use in future sessions, run this function with `install = TRUE`.
# "install=T" stores your api_key
# If stored, checking api_key as follows:
# readRenviron("~/.Renviron")
# Sys.getenv("CENSUS_API_KEY")
View(load_variables(2019, "acs5", cache = TRUE))
DC_INCOME <- get_acs(geography = "tract",
variables = "B06011_001",
state = "District of Columbia",
geometry = TRUE)
## Getting data from the 2015-2019 5-year ACS
head(DC_INCOME)
palette <- colorBin(palette = "Blues",
domain = DC_INCOME$estimate, bins=10)
DC_INCOME %>%
st_transform(crs = "+init=epsg:4326") %>%
leaflet(width = "100%") %>%
addProviderTiles(provider = "CartoDB.Positron") %>%
addPolygons(popup = ~GEOID,
color = "black",
weight = 1)%>%
addPolygons(popup = ~ str_extract(NAME, "^([^,]*)"),
stroke = FALSE,
smoothFactor = 0,
fillOpacity = 0.7,
color = ~ palette(estimate)) %>%
addLegend("bottomleft",
pal = palette,
values = ~ estimate,
title = "Median income - Tract",
labFormat = labelFormat(prefix = "$"),
opacity = 1)
## Warning in CPL_crs_from_input(x): GDAL Message 1: +init=epsg:XXXX syntax is
## deprecated. It might return a CRS with a non-EPSG compliant axis order.
## Warning in RColorBrewer::brewer.pal(max(3, n), palette): n too large, allowed maximum for palette Blues is 9
## Returning the palette you asked for with that many colors
## Warning in RColorBrewer::brewer.pal(max(3, n), palette): n too large, allowed maximum for palette Blues is 9
## Returning the palette you asked for with that many colors
## Warning in RColorBrewer::brewer.pal(max(3, n), palette): n too large, allowed maximum for palette Blues is 9
## Returning the palette you asked for with that many colors
DC_BLACK <- get_acs(geography = "tract",
variables = "B01001B_001",
state = "District of Columbia",
geometry = TRUE,
summary_var="B01001_001")
## Getting data from the 2015-2019 5-year ACS
pal1 <- colorBin(palette = "Greys",
domain = DC_BLACK$summary_est, bins=10)
DC_BLACK %>%
st_transform(crs = "+init=epsg:4326") %>%
leaflet(width = "100%") %>%
addProviderTiles(provider = "CartoDB.Positron") %>%
addPolygons(popup = ~GEOID,
color = "black",
weight = 1)%>%
addPolygons(popup = ~ str_extract(NAME, "^([^,]*)"),
stroke = FALSE,
smoothFactor = 0,
fillOpacity = 0.7,
color = ~ pal1(summary_est)) %>%
addLegend("bottomleft",
pal = pal1,
values = ~ summary_est,
title = "Total population - Tract",
opacity = 1)
pal2 <- colorBin(palette = "BuGn",
domain = DC_BLACK$estimate/DC_BLACK$summary_est*100,
bins=10)
DC_BLACK %>%
st_transform(crs = "+init=epsg:4326") %>%
leaflet(width = "100%") %>%
addProviderTiles(provider = "CartoDB.Positron") %>%
addPolygons(popup = ~GEOID,
color = "black",
weight = 1)%>%
addPolygons(popup = ~ str_extract(NAME, "^([^,]*)"),
stroke = FALSE,
smoothFactor = 0,
fillOpacity = 0.7,
color = ~ pal2(estimate/summary_est*100)) %>%
addLegend("bottomleft",
pal = pal2,
values = ~ estimate/summary_est*100,
title = "Proportion of Blacks - Tract",
labFormat = labelFormat(suffix="%"),
opacity = 1)
## Warning in RColorBrewer::brewer.pal(max(3, n), palette): n too large, allowed maximum for palette BuGn is 9
## Returning the palette you asked for with that many colors
## Warning in RColorBrewer::brewer.pal(max(3, n), palette): n too large, allowed maximum for palette BuGn is 9
## Returning the palette you asked for with that many colors
## Warning in RColorBrewer::brewer.pal(max(3, n), palette): n too large, allowed maximum for palette BuGn is 9
## Returning the palette you asked for with that many colors